from selenium import webdriver
from selenium.webdriver import ActionChains


class TestActionChainsCase:
    def setup(self):
        self.driver = webdriver.Chrome()
        self.action = ActionChains(self.driver)

    def test_actionchains(self):
        self.driver.get("https://sahitest.com/demo/clicks.htm")
        self.driver.maximize_window()
        single_click = self.driver.find_element_by_xpath("/html/body/form/input[3]")
        double_click = self.driver.find_element_by_xpath("/html/body/form/input[2]")
        right_click = self.driver.find_element_by_xpath("/html/body/form/input[4]")
        self.action.click(single_click)
        self.action.double_click(double_click)
        self.action.context_click(right_click)
        self.action.perform()

    def test_drag_and_drop(self):
        self.driver.get("https://sahitest.com/demo/dragDropMooTools.htm")
        self.driver.maximize_window()
        drag_ele = self.driver.find_element_by_id("dragger")
        drop_ele = self.driver.find_element_by_xpath("/html/body/div[2]")
        self.action.drag_and_drop(drag_ele,drop_ele).perform()
        # self.action.click_and_hold(drag_ele).release(drop_ele).perform()
        # self.action.click_and_hold(drag_ele).move_to_element(drop_ele).perform()

    def teardown(self):
        self.driver.quit()